package com.hero.provide.service;

import com.hero.common.UserEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 * 在spring cloud 中，该模块属于业务模块，但是为外提供服务
 * 所以，该服务就相当于controller 层
 */
@RestController
public class UserService {

    Logger logger = LoggerFactory.getLogger(UserService.class);

    @RequestMapping( value = "/login",method = RequestMethod.GET)
    public String login(@RequestParam("count") int count) throws Exception{
        logger.info("---------------->>> 当前为provide1 提供服务login" + count);
        return " 用户已验证。";
    }

    @RequestMapping( value = "/loginParam",method = RequestMethod.POST)
    public String login(@RequestParam("userName") String userName,@RequestParam("password") String password) throws Exception{
        logger.info("---------------->>> 当前为provide1 提供服务loginParam");
        if(userName.equals("admin") && password.equals("123456")){
            return " 用户已验证成功。";
        }else{
            return "账号或者密码错误.";
        }
    }

    @RequestMapping( value = "/loginJson",method = RequestMethod.POST)
    public String login(@RequestBody UserEntity userInfo) throws Exception{
        logger.info("---------------->>> 当前为provide1 提供服务loginJson");
        if(userInfo.getUserName().equals("admin") && userInfo.getPassword().equals("123456")){
            return " 用户已验证成功。";
        }else{
            return "账号或者密码错误.";
        }
    }
}
